<?php

namespace App\Http\Middleware;

use App\User;
use Closure;

class LoginMiddleware {
	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next) {
		//request变量 记录所有的请求参数
		if (!session('isAdmin')) {
			return redirect('/login/admin');
		}

		if (!session('isAdmin') && !session('id')) {
			return redirect('/login/admin');
		} else {
			$user = User::find(session('id'));
			if (!$user || $user->status == 0 || $user->auth < 3) {
				return redirect('/login/admin');
			}
		}
		return $next($request);
	}
}
